gamma   = 10;
psi     = 1.5;

phi_id0  = para(1);
phi_id1  = para(2);
phi_sig0 = para(3);
phi_sig1 = para(4);
phi_mu   = para(5);
a        = para(6);
b        = para(7);

rho_CE  = 0.2; % corr[eps_c,eps_i]

mu_C    = [-0.19513 -0.19513 0.19393 0.19393]'/100;
sig_C   = [0.44071 1.31462 0.44071 1.31462]'/100;

P       = [0.97679 0.00103 0.02215 0.00002;
           0.00386 0.97397 0.00009 0.02209;
           0.00282 0.00000 0.99612 0.00105;
           0.00001 0.00281 0.00393 0.99325];

P       = P./sum(P,2);
nS      = 4;

% ergodic distribution
stat        = P^1e6;
stat        = stat(1,:)';

% Computation
Tmax        = 12;   % maximum CDS maturity (in months)
Tmax_CDS    = 60;   % maximum CDS maturity (in months)
Tmax_IV     = 12;
k_min       = 0.1;
k_max       = 500;
nK          = 8000;
nK_fine     = 1*nK;
nE          = 51;

meth        = 'linear';
ex_meth     = 'linear';

% Convergence for VFI
prec        = 1e-6;

% Frictions
tau_i       = 0.296; % tax rate on interest income
tau_d       = 0.112; % tax rate on dividend income
tau_c       = 0.329; % tax rate on corporate earnings

xi_d        = 0.01; % debt issuance fee
xi_e        = 0.04; % equity issuance costs

sig_Xid     = phi_id0  + phi_id1  * (sig_C-stat'*sig_C);
sig_XS      = phi_sig0 + phi_sig1 * (sig_C-stat'*sig_C);

sig_X       = sqrt( sig_XS.^2 + sig_Xid.^2 );

mu_X        = (mu_C-stat'*mu_C)*phi_mu + stat'*mu_C;
mu_XQ       = mu_X - gamma*rho_CE*sig_XS.*sig_C;

SR          = mu_C./sig_C;
E_SR        = SR'*stat;
SR          = SR - E_SR;

omega       = a - b*SR;
omega       = min(1,max(omega,0));

